<?php
$anio = $_REQUEST['anio'];
//$nomnotaria = "Nombre de la Notaria";
$nomnotaria = " ";

?>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        
        	<title>.:: REPORTE UIF - IAOC ::.</title>
            <style type="text/css">
			#logo_emp{
				float:left;
				padding:0px;
				margin:0px;
				margin-top:10px;
				margin-left:10px;
				}
			#fec_actual{
				float:right;
				padding:0px;
				margin:0px;
				margin-top:10px;
				margin-right:10px;
				}	
			</style>
	</head>
        <body>
        <div><div id="logo_emp"><?php echo $nomnotaria ?></div> <!--<div id="fec_actual">Fecha: <?php echo $fec=date("d/m/Y H:m:s"); ?></div>--></div>        
<p align="center"><br><br>
     <strong>REPORTE DE CONTRATOS PENDIENTES DE CONCLUSION DE FIRMAS</strong></p>
<p align="center"><strong>Listado del <?php echo $fechade ?> al <?php echo $fechaa ?></strong></p>

<TABLE  BORDER=1 CELLSPACING=0 CELLPADDING=0 align="center">
            
       <!--<TR><TD width="70" height="19">Numero</TD><TD width="86">Fec. Ingr.</TD><TD width="86">Fec. Dilig.</TD><TD width="93">Zona</TD><TD width="171">&nbsp; Remitente</TD><TD width="275">&nbsp; Destinatario</TD></TR>-->
       
       		  <TR>
                <TD align='CENTER' width="100" height="19">Tipo</td>
                <TD align='CENTER' width="50">Kardex</td>
                <TD align='CENTER' width="70">Fec.Escritura</td>
                <TD align='CENTER' width="93">Num.Escritura</td>
                <TD align='CENTER' width="171">Contrato</td>
                <TD align='CENTER' width="275">Contratantes</td>
              </TR>
       
       
</TABLE>
<?php 
include('../conexion.php');
$desde   = $_REQUEST['fechade'];
$hasta   = $_REQUEST['fechaa'];
$tipokar = $_REQUEST['tipokar'];

if($tipokar=='')
{
	$consulta = mysql_query("SELECT IF(DATE_FORMAT(kardex.fechaescritura,'%d/%m/%Y')='00/00/0000','',DATE_FORMAT(kardex.fechaescritura,'%d/%m/%Y')) AS 'fec_escritura_2', tipokar.nomtipkar AS 'tipo'  ,kardex.*   FROM kardex INNER JOIN tipokar ON tipokar.idtipkar = kardex.idtipkar WHERE kardex.fechaconclusion='' AND (fechaescritura BETWEEN '$desde' AND '$hasta') order by kardex.kardex desc", $conn) or die(mysql_error());
}
	else
	{
		$consulta = mysql_query("SELECT tipokar.nomtipkar AS 'tipo'  ,kardex.*   FROM kardex INNER JOIN tipokar ON tipokar.idtipkar = kardex.idtipkar WHERE kardex.idtipkar='$tipokar' AND kardex.fechaconclusion='' AND (fechaescritura BETWEEN '$desde' AND '$hasta') order by fechaescritura asc", $conn) or die(mysql_error());			
	}

while($row = mysql_fetch_array($consulta)){

echo"<TABLE BORDER='1' CELLPADDING='0' CELLSPACING='0' ALIGN='CENTER'>
<TR>
    <TD WIDTH='100' valign='top'>".$row['tipo']."</TD>
	<TD WIDTH='50' valign='top'>".$row['kardex']."</TD>
    <TD WIDTH='70' valign='top'>". $row['fec_escritura_2']."</TD>
	  <TD WIDTH='93' valign='top'>".$row['numescritura']."</TD>
	  <TD WIDTH='171' valign='top'>".$row['contrato']."</TD>
    <TD WIDTH='275' valign='top'>"; 
	$kardex=$row['kardex'];
	$consultr = mysql_query("SELECT * FROM contratantes WHERE kardex='$kardex' and indice='1'", $conn) or die(mysql_error());
	while($row2 = mysql_fetch_array($consultr)){
	  $contratante=$row2['idcontratante'];
	  $consultrr = mysql_query("SELECT * FROM cliente2 WHERE idcontratante='$contratante' order by idcontratante asc", $conn) or die(mysql_error());
	  while($row3 = mysql_fetch_array($consultrr)){
	   if($row3['tipper']=="N") { echo $row3['apepat']." ".$row3['apemat'].", ".$row3['prinom']." ".$row3['segnom']."<BR>";  }else {  echo str_replace("*","&",str_replace("?","'",$row3['razonsocial']))."<BR>"; }
	
	  }
	}
	echo"</TD></TR></TABLE>";
}
?>
</body>
</html>